 
// Source File Name:   SET_ADImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.AD;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.SET_AD;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Set;


//            SETCommonImpl, ANYImpl, BLImpl, CSImpl,
//            TYPEImpl

public class SET_ADImpl extends SETCommonImpl
    implements SET_AD
{

    public static final String RCS_ID = "$Header: SET_ADImpl.java 1.0 2006/09/16 09:23:42 amchanda noship $";
    private static final SET_AD nullNI = new SET_ADImpl(CSImpl.valueOf("NI"));
    private static final SET_AD nullOTH = new SET_ADImpl(CSImpl.valueOf("OTH"));
    private static final SET_AD nullNINF = new SET_ADImpl(CSImpl.valueOf("NINF"));
    private static final SET_AD nullPINF = new SET_ADImpl(CSImpl.valueOf("PINF"));
    private static final SET_AD nullUNK = new SET_ADImpl(CSImpl.valueOf("UNK"));
    private static final SET_AD nullASKU = new SET_ADImpl(CSImpl.valueOf("ASKU"));
    private static final SET_AD nullNAV = new SET_ADImpl(CSImpl.valueOf("NAV"));
    private static final SET_AD nullMSK = new SET_ADImpl(CSImpl.valueOf("MSK"));
    private static final SET_AD nullNA = new SET_ADImpl(CSImpl.valueOf("NA"));
    private static final SET_AD nullNASK = new SET_ADImpl(CSImpl.valueOf("NASK"));

    public static SET_AD valueOf(AD aad[])
    {
        return new SET_ADImpl(aad);
    }

    public static SET_AD valueOf(AD ad)
    {
        return new SET_ADImpl(ad);
    }

    public static SET_AD valueOf(Set set)
    {
        return new SET_ADImpl(set);
    }

    public static SET_AD nullSET_AD()
    {
        return new SET_ADImpl(((CS) (null)));
    }

    protected SET_ADImpl(AD aad[])
    {
        if(aad == null)
            throw ANYImpl.newNullException("SET<AD>", "constructor", "elements");
        for(int i = 0; i < aad.length; i++)
            if(aad[i] != null && aad[i].isNull().isFalse())
                mSet.add(aad[i]);

    }

    protected SET_ADImpl(AD ad)
    {
        if(ad == null || ad.isNull().isTrue())
        {
            throw ANYImpl.newNullException("SET<AD>", "constructor", "element");
        } else
        {
            mSet.add(ad);
            return;
        }
    }

    public SET_ADImpl(Set set)
    {
        super(set);
    }

    public SET_ADImpl(CS cs)
    {
        super(cs);
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof SET_AD))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            SET_AD set_ad = (SET_AD)any;
            return BLImpl.valueOf(equalsSet(set_ad.toSet()));
        }
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.SET_AD;
    }

    protected boolean verifyItem(Object obj)
    {
        return (obj instanceof AD) && ((AD)obj).nonNull().isTrue();
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public static SET_AD nullSET_AD(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
